/**
 * Created by baidm in 2021/2/6 on 12:41
 */
/**
 * leetcode第三题：无重复字符的最长子串
 * input:s="abcabcaa",out:3
 * input:s="abcaaabcd",out:4
 * input:s="pwwkew",out:3
 * input:s="",out:0
 * @param s
 * @returns {number}
 */
function maxSubStr(s = "") {
    let sArr = s.split("");
    if (!sArr.length) return 0;
    let max = 0, map = {};
    for (let i = 0; i < sArr.length; i++) {
        if (!map[sArr[i]]) {
            map[sArr[i]] = true;
        } else {
            if (max < Object.keys(map).length) {
                max = Object.keys(map).length;
            }
            map = {};
            map[sArr[i]] = true;
        }
    }
    max = max < Object.keys(map).length ? Object.keys(map).length : max;
    return max;
}